for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import Relation from "../Relation";
import {ModelStaticInterface} from "../../../JeloquentInterfaces";
import ForeignKey from "../Field/ForeignKey";
/**
*
*/
export default class HasOne extends Relation {
constructor(model: ModelStaticInterface) {
super(model);
}
get originalValue(): unknown {
return this.getValueByParentKey('originalPrimaryKey');
get value(): unknown {
return this.getValueByParentKey('primaryKey');
getRelationalFields():Array<ForeignKey> {
return [];
setName(): HasOne {
this.foreignKey = `${this.$parent.snakeCaseClassName}_id`;
return this;
private getValueByParentKey(parentProperty) {
const keyIndex = this.model.getIndexByKey(this.foreignKey);
return globalThis.Store.database().find(this.model.className,
[...keyIndex.get(`${this.$parent[parentProperty]}`)?.values() ?? []]
).first();